<?php
/*
Template Name: Premium Profile 3
*/

?>

<script type="text/javascript">
function validateEmailForm(){
	
	if(jQuery("#fullname").val()==""){
		alert('Please Provide Your Full Name');
		jQuery("#fullname").focus();
		return false;
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(jQuery("#email").val()) == false){
		alert('Please Provide Your Valid Email Address');
		jQuery("#email").focus();
		return false;
	}

	if(jQuery("#message").val()==""){
		alert('Please Provide Your Message');
		jQuery("#message").focus();
		return false;
	}
	
	return true;	
}
</script>


<?php 
$emailAddress=get_post_meta($post->ID, "emailAddress", true);

$send_email = dirname(__FILE__).'/sendemail.php';
include($send_email)
?>

<?php
	$emailAddress=get_post_meta($post->ID, "emailAddress", true);
	$phoneNumber=get_post_meta($post->ID, "phoneNumber", true);
	$contactPerson=get_post_meta($post->ID, "contactPerson", true);
	$siteURL=get_post_meta($post->ID, "siteURL", true);
	$youTubeVideo=get_post_meta($post->ID, "youTubeVideo", true);
	$address=get_post_meta($post->ID, "address", true);
	$about_us =get_post_meta($post->ID, "company_info", true);
	$video =get_post_meta($post->ID, "youTubeVideo", true);
	
	
	//getting featured products IMAGE, LINK, TITLE (STRING)
	$featProducts =get_post_meta($post->ID, "company_featured_products");
	
	
	if($siteURL == "")
	{
		$siteURL = 'N/A';
	}elseif(!isValidURL($siteURL))
	{
		$siteURL = '<a style="text-decoration:underline" target="_new" href="http://'.$siteURL.'">'.$siteURL.'</a>';
	}
	else
	{
		$siteURL = '<a style="text-decoration:underline" target="_new" href="'.$siteURL.'">'.$siteURL.'</a>';
	}
	
	
function isValidURL($url)
{
	return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}

?>

<div class="archive">

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

            <div class="hentry-meta">
                <h1><?php if ( has_post_thumbnail() ) the_post_thumbnail('company-logo'); ?><?php the_title(); ?></h1>
            </div>
            
            <!-- feature slider -->
<?php

$topListed = get_post_meta($post->ID, 'top_listed');
$arrTopPosts = array();
$postIDs = array();
foreach($topListed as $tl)
{
	$breakAPart = explode(',',$tl);
	$image = $breakAPart['0'];
	$link  = $breakAPart['1'];
	$title = $breakAPart['2']
	
	/* $arrTopPosts[$breakAPart[0]] = $breakAPart[1];
	$postIDs[] = $breakAPart[0];
          $args = array(
                'post__in'=> $postIDs
            );
            query_posts($args);
            if ( have_posts() ) :*/
		
        ?>
        <div id="mainposts">
            <ul>
                <?php while (have_posts() ) : the_post(); 
			
				$mainImage = $arrTopPosts[get_the_ID()];		//get_post_meta(get_the_ID(), 'top_image_url', true);
				?>
                <li>
                    <div class="mainpost">
                        <?php //if ( has_post_thumbnail() ) the_post_thumbnail('slide-magazine'); ?>
                        <img width="620" height="365" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" class="attachment-slide-magazine wp-post-image" src="<?php echo trim($mainImage)?>">
                        <div class="mainpost-container">
                            <div class="bg"></div>
                            <div class="mainpost-data">
                                <!--<div class="mainpost-meta"><?php echo get_the_date(); ?> &middot; <?php comments_popup_link ( __('0 Comments', 'unspoken'), __('1 Comment', 'unspoken'), __('% Comments', 'unspoken'), '', __('Comments off', 'unspoken')); ?> &middot; <?php the_category(', '); ?></div>-->
                                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                <?php the_excerpt(); ?>
                            </div>
                        </div>
                    </div>
                </li>
                <?php
                    /*endwhile;
                    wp_reset_query();*/
					}
                ?>
            </ul>
            <a href="javascript: void(0);" class="prev"></a>
            <a href="javascript: void(0);" class="next"></a>
        </div>
        <?php //endif; ?>
        <div class="clearfix"></div>
                
<!-- feature slider ends -->  

            <div class="hentry-content clear" style="width:auto">

				<h4 class="widget-title">Contact</h4>
				<div class="half profile-contact">
					 <p><strong>Address:</strong> <?php echo $address?></p>
					 <p><strong>Phone No:</strong> <?php echo $phoneNumber?></p>
					 <p><strong>Email:</strong> <a href="mailto:<?php echo $emailAddress?>"><?php echo $emailAddress?></a></p>
                     <p><strong>Website:</strong> <?php echo $siteURL?></p>
					 
				</div>
				<div class="half">
					<form action="<?php $_SERVER['PHP_SELF']?>" method="post" onsubmit="return validateEmailForm()">
                    <input type="hidden" name="toAddress" value="<?php echo $emailAddress ?>" />
						<input name="fullname" type="text" class="field-text" id="fullname" placeholder="Your Name">
					  <input name="email" type="text" class="field-text" id="email" placeholder="Your Email">
					  <textarea name="message" class="field-text" id="message"></textarea>
                        <input name="emailSender" type="submit" class="field-button" id="emailSender" value="Send Message" />
					</form>
				</div>
				<div class="clearfix"></div>
                
				<div class="half">
					<a href="#"><h4 class="widget-title">About us</h4></a>
					<p><?php echo $about_us?></p>
				</div>

				<div class="half">
					<a href="#"><h4 class="widget-title">Featured Products</h4></a>

					<ul class="featured_products">
                    <?php
					foreach($featProducts as $prod):
					$prod = explode(',', $prod);
					$image = $prod['0'];
					$link  = $prod['1'];
					$title = $prod['2']
					?>
						<li><img width="140" height="90" src="<?php echo $image?>" alt="<?php echo $title?>">
                         <a href="<?php echo $link?>"><?php echo $title?></a></li>
					<?php
					endforeach;
					?>
					</ul>

				</div>
				<div class="clearfix" style="width: 100%; clear: both; float: none;"></div>
                
                <h4 class="widget-title">Video</h4>
                <iframe width="600" height="335" src="http://www.youtube.com/embed/<?php echo $video?>" frameborder="0" allowfullscreen></iframe>	
			 </div>

        </div> <!-- .page -->

    <?php endwhile; // end of the loop. ?>

</div>